package io.demo.message.serial;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class SerializedObjectTestBase<T> {

  private final Logger logger = LoggerFactory.getLogger(getClass());

  protected abstract SerializedObject<T> serializedObject(T object);

  protected abstract T provide();

  @Test
  public void doSerialization() {
    T object = provide();
    SerializedObject<T> serializedObject = serializedObject(object);

    logger.info("Byte-Length: {}", serializedObject.getByteArrayLength());
    assertThat(serializedObject).isNotNull();
    assertThat(serializedObject.getByteArray()).isNotEmpty();
  }

  @Test
  public void doDeserialization() {
    T object = provide();
    SerializedObject<T> serializedObject = serializedObject(object);
    T reversed = serializedObject.reverse();
    assertThat(reversed).isEqualTo(object);
  }
}
